<?php

namespace app\common\model\photo;

use think\facade\Config;
use app\common\model\Base;

class Pay extends Base
{
    protected $name = 'photo_pay';

    // 相册
    const ALBUM = 1;

    // 图片
    const PHOTO = 2;

    // 阅后即焚
    const READ_REMOVE = 3;

    public function getAlbumList($condition = [], $condition_or = [], $page = -1, $sort = 'p.pay_time desc')
    {
        if ($page < 0) {
            $page = Config::get('paginate.list_rows');
        }

        $condition[] = ['p.type', '=', self::ALBUM];
        $res = $this->alias('p')->where($condition)
            ->where(function ($query) use($condition_or){
                $query->whereOr($condition_or);
            })
            ->join('member m1', 'p.member_id = m1.id', 'left')
            ->join('member m2', 'p.view_member_id = m2.id', 'left')
            ->field('p.*, m1.nickname, m2.nickname view_nickname, m2.avatar')
            ->order($sort);
        if ($page) {
            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            return $res->items();
        } else {
            return $res->select()->toArray();
        }
    }

    public function getPhotoList($condition = [], $condition_or = [], $page = -1, $sort = 'p.pay_time desc')
    {
        if ($page < 0) {
            $page = Config::get('paginate.list_rows');
        }

        $condition[] = ['p.type', 'IN', self::PHOTO .', '. self::READ_REMOVE];
        $res = $this->alias('p')->where($condition)
            ->where(function ($query) use($condition_or){
                $query->whereOr($condition_or);
            })
            ->join('member_file f', 'p.file_id=f.id', 'left')
            ->field('p.*, f.url')
            ->order($sort);
        if ($page) {
            $res = $res->paginate($page, false, ['query' => request()->param()]);
            $this->page_info = $res;
            return $res->items();
        } else {
            return $res->select()->toArray();
        }
    }
}